#include <array>

template<int LEVEL_CNT>
class Checker {
private:
    int comboDays = 0;
    int lastCheckDate = 0;
    int activeLevel = 0;
    int credits = 0;

public:
    using CheckerArray = std::array<int, LEVEL_CNT>;

    CheckerArray daysOfLevel;
    CheckerArray creditsForActiveLevel;

    Checker(CheckerArray const & days, CheckerArray const & credits)
        : daysOfLevel(days)
        , creditsForActiveLevel(credits) {}

    auto checkIn(int date) {
        if (date - lastCheckDate == 1) {
            comboDays += 1;
        } else {
            comboDays = 1;
            activeLevel = 0;
        }
        lastCheckDate = date;

        if (activeLevel < LEVEL_CNT && comboDays == daysOfLevel[activeLevel]) {
            activeLevel += 1;
        }

        credits += creditsForActiveLevel[activeLevel - 1];
    }

    [[nodiscard]] auto getCredits() const { return credits; }
};

#include <iostream>

int main() {
    using MyChecker = Checker<6>;

    int n;
    std::cin >> n;

    MyChecker::CheckerArray creditsForActiveLevel;
    for (auto & val : creditsForActiveLevel) { std::cin >> val; }

    MyChecker checker({1, 3, 7, 30, 120, 365}, creditsForActiveLevel);

    for (int flag, date = 1; date <= n; ++date) {
        std::cin >> flag;
        if (flag == 1) { checker.checkIn(date); }
    }

    std::cout << checker.getCredits() << "\n";
}
